# surfparc_mass_images_20070917.bash
# mass images

resultsdir=/mri_projects/ASD_Analysis/Results

function combineimg() {
  src_sub_dir=$1
  des_sub_dir=$2
  fig_type=$3

  lh_front_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_lh_lat.tif"
  lh_back_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_lh_med.tif"
  lh_asd_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_lh_front_back.tif"
  convert $lh_front_file $lh_back_file -gravity east -append $lh_asd_file
  #
  lh_front_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_lh_lat.png"
  lh_back_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_lh_med.png"
  lh_asd_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_lh_front_back.png"
  convert $lh_front_file -transparent black $lh_front_trans_file
  convert $lh_back_file -transparent black $lh_back_trans_file
  convert $lh_front_trans_file $lh_back_trans_file -gravity east -append $lh_asd_trans_file

  rh_front_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_rh_lat.tif"
  rh_back_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_rh_med.tif"
  rh_asd_file=$resultsdir"/screencaps/"$src_sub_dir"/fsaverage4_"$fig_type"_rh_front_back.tif"
  convert $rh_front_file $rh_back_file -gravity east -append $rh_asd_file
  #
  rh_front_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_rh_lat.png"
  rh_back_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_rh_med.png"
  rh_asd_trans_file=$resultsdir"/screencaps/"$src_sub_dir"_rh_front_back.png"
  convert $rh_front_file -transparent black $rh_front_trans_file
  convert $rh_back_file -transparent black $rh_back_trans_file
  convert $rh_front_trans_file $rh_back_trans_file -gravity east -append $rh_asd_trans_file

  final_name=$resultsdir"/screencaps/wb_"$src_sub_dir"_fs4_"$fig_type".png"
  convert $lh_asd_file $rh_asd_file -gravity north +append $final_name

  final_name=$resultsdir"/screencaps/wb_trans_"$src_sub_dir"_fs4_"$fig_type".png"
  convert $lh_asd_trans_file $rh_asd_trans_file -gravity north +append $final_name

  rm $lh_front_trans_file
  rm $lh_back_trans_file
  rm $rh_front_trans_file
  rm $rh_back_trans_file
  rm $lh_asd_trans_file
  rm $rh_asd_trans_file

  lh_front_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_lh_lat.tif"
  lh_back_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_lh_med.tif"
  lh_hc_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_lh_front_back.tif"
  convert $lh_front_file $lh_back_file -gravity east -append $lh_hc_file
  #
  lh_front_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_lh_lat.png"
  lh_back_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_lh_med.png"
  lh_asd_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_lh_front_back.png"
  convert $lh_front_file -transparent black $lh_front_trans_file
  convert $lh_back_file -transparent black $lh_back_trans_file
  convert $lh_front_trans_file $lh_back_trans_file -gravity east -append $lh_asd_trans_file

  rh_front_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_rh_lat.tif"
  rh_back_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_rh_med.tif"
  rh_hc_file=$resultsdir"/screencaps/"$des_sub_dir"/fsaverage4_"$fig_type"_rh_front_back.tif"
  convert $rh_front_file $rh_back_file -gravity east -append $rh_hc_file
  #
  rh_front_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_rh_lat.png"
  rh_back_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_rh_med.png"
  rh_asd_trans_file=$resultsdir"/screencaps/"$des_sub_dir"_rh_front_back.png"
  convert $rh_front_file -transparent black $rh_front_trans_file
  convert $rh_back_file -transparent black $rh_back_trans_file
  convert $rh_front_trans_file $rh_back_trans_file -gravity east -append $rh_asd_trans_file

  final_name=$resultsdir"/screencaps/wb_"$des_sub_dir"_fs4_"$fig_type".png"
  convert $lh_hc_file $rh_hc_file -gravity north +append $final_name

  final_name=$resultsdir"/screencaps/wb_trans_"$des_sub_dir"_fs4_"$fig_type".png"
  convert $lh_asd_trans_file $rh_asd_trans_file -gravity north +append $final_name

  rm $lh_front_trans_file
  rm $lh_back_trans_file
  rm $rh_front_trans_file
  rm $rh_back_trans_file
  rm $lh_asd_trans_file
  rm $rh_asd_trans_file

  final_name=$resultsdir"/screencaps/wb_"$src_sub_dir"_"$des_sub_dir"_fs4_"$fig_type".png"
  convert $lh_asd_file $rh_asd_file $lh_hc_file $rh_hc_file -gravity north +append $final_name

  rm $lh_asd_file
  rm $rh_asd_file
  rm $lh_hc_file
  rm $rh_hc_file
}

function combinehcimg() {
  sbjid=$1
  fig_type=$2

  lh_front_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_lh_lat.tif"
  lh_back_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_lh_med.tif"
  lh_hc_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_lh_front_back.tif"
  convert $lh_front_file $lh_back_file -gravity east -append $lh_hc_file
  #
  lh_front_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_lh_lat.png"
  lh_back_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_lh_med.png"
  lh_hc_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_lh_front_back.png"
  convert $lh_front_file -transparent black $lh_front_trans_file
  convert $lh_back_file -transparent black $lh_back_trans_file
  convert $lh_front_trans_file $lh_back_trans_file -gravity east -append $lh_hc_trans_file

  rh_front_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_rh_lat.tif"
  rh_back_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_rh_med.tif"
  rh_hc_file=$resultsdir"/screencaps/"$sbjid"_HC/fsaverage4_"$fig_type"_rh_front_back.tif"
  convert $rh_front_file $rh_back_file -gravity east -append $rh_hc_file
  #
  rh_front_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_rh_lat.png"
  rh_back_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_rh_med.png"
  rh_hc_trans_file=$resultsdir"/screencaps/"$sbjid"_HC_rh_front_back.png"
  convert $rh_front_file -transparent black $rh_front_trans_file
  convert $rh_back_file -transparent black $rh_back_trans_file
  convert $rh_front_trans_file $rh_back_trans_file -gravity east -append $rh_hc_trans_file

  final_name=$resultsdir"/screencaps/wb_"$sbjid"_HC_fs4_"$fig_type".png"
  convert $lh_hc_file $rh_hc_file -gravity north +append $final_name

  final_trans_name=$resultsdir"/screencaps/wb_trans_"$sbjid"_HC_fs4_"$fig_type".png"
  convert $lh_hc_trans_file $rh_hc_trans_file -gravity north +append $final_trans_name

  rm $lh_front_trans_file
  rm $lh_back_trans_file
  rm $rh_front_trans_file
  rm $rh_back_trans_file
  rm $lh_hc_trans_file
  rm $rh_hc_trans_file

  rm $lh_hc_file
  rm $rh_hc_file
}

combineimg OHSU_ASD_before OHSU_ASD_after 'if'
combineimg OHSU_HC_before OHSU_HC_after 'if'
combineimg OHSU_ASD_before OHSU_HC_before 'if'
combineimg OHSU_ASD_after OHSU_HC_after 'if'
# combineimg KKI 'if'
# combinehcimg STD 'if'
